#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=998244353;

struct node{
    int l;
    ll num;
};

struct node1{
    int l;
    int po;
};

void solve(){
    int n;
    cin>>n;
    vector<node>vec;
    vector<node1>zhi;
    stack<int>vis;
    int po=-1;
    int zhipo=-1;
    ll sum=0;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        if(s=="Push"){
            ll num;
            cin>>num;
            vec.push_back({po,num});
            po=vec.size()-1;
            sum=(num+sum)%mod;
        }
        else if(s=="Pop"){
            sum-=vec[po].num;
            if(sum<0)sum+=mod;
            po=vec[po].l;
            if(po==-1&&zhipo!=-1){
                po=zhi[zhipo].po;
                zhipo=zhi[zhipo].l;
                if(zhipo==-1&&vis.size()!=0){
                    zhipo=vis.top();
                    vis.pop();
                }
            }
        }
        else {
            zhi.push_back({zhipo,po});
            zhipo=zhi.size()-1;
            vis.push(zhipo);
            sum=(sum*2LL)%mod;
        }
        cout<<sum<<endl;
        if(i==4){
            for(int j=0;j<zhi.size();j++)cout<<zhi[j].l<<" "<<zhi[j].po<<endl;
        }
    }
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    int _=1;
    //cin>>_;
    while(_--){
        solve();
    }
    return 0;
}